<template>
    <view @click="handleClipboard" class="copy">复制</view>
</template>

<script>
export default {
    props: {
        text: {
            type: String | Number,
            default: ''
        }
    },
    methods: {
        handleClipboard() {
            if (!this.text) {
            } else {
                uni.setClipboardData({
                    data: this.text,
                    showToast: false,
                    success: () => {
                        uni.uToast({
                            type: 'success',
                            message: '复制成功'
                        });
                        this.$emit('copy');
                    },
                    fail: () => {
                        uni.uToast({
                            type: 'error',
                            message: '复制失败'
                        });
                    }
                });
            }
        }
    }
};
</script>

<style lang="scss" scoped>
.copy {
    padding: 8rpx 12rpx;
    border-radius: 8rpx;
    background: #dde2fd;
    color: #0069ff;
    font-weight: 600;
    font-size: 20rpx;
}
</style>
